package com.ihelp.controller;

import com.ihelp.entities.CommonResult;
import com.ihelp.pojo.Hospital;
import com.ihelp.service.HospitalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author LiuZiMing
 * @since 2023-05-23
 */
@RestController
@Slf4j
@RequestMapping("/hospital")
public class HospitalController {
    @Autowired
    private HospitalService hospitalService;

    @GetMapping("/all")
    public CommonResult getAllHospital() {
        List<Hospital> allHospital = hospitalService.getAllHospital();
        return new CommonResult<>(200, "获取所有医院成功", allHospital);

    }

    @GetMapping("/id/{id}")
    public CommonResult getHospitalById(@PathVariable Integer id) {
        Hospital hospitalById = hospitalService.getHospitalById(id);
        if (hospitalById != null) {
            return new CommonResult<>(200, "根据id:" + id + ",获取医院成功", hospitalById);
        } else {
            return new CommonResult<>(204, "根据id:" + id + ",未找到医院");
        }


    }

}
